﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Data;
using QuanLyKho.BanHang;
using QuanLyKho.Control;
using QuanLyKho.DKChung;
using QuanLyKho.KCS;
using QuanLyKho.PhanQuyen;
using QuanLyKho.PhongCat;
using QuanLyKho.PhongGiaCong;
using QuanLyKho.PhongHoanThien;
using QuanLyKho.PhongLenh;
using QuanLyKho.PhongMau;
using QuanLyKho.PhongMayKhoan;
using QuanLyKho.PhongThanhPham;
using QuanLyKho.QuanLyKho;

namespace QuanLyKho
{
    public partial class Main : Form
    {
        public static string UserID = "NV";
        private UserControl _userControl;
        public Main()
        {
            InitializeComponent();
            CheckTinNhan();
        }

        public void LoadUserControl(UserControl fileControl)
        {
            _userControl = fileControl;
            foreach (var control in plMain.Controls)
            {
                var dispose = control as UserControl;
                if (dispose != null)
                {
                    dispose.Dispose();
                }
            }
            _userControl.Dock = DockStyle.Fill;
            plMain.Controls.Add(_userControl);
        }

        private void timeTinNhan_Tick(object sender, EventArgs e)
        {
            CheckTinNhan();
        }

        public void CheckTinNhan()
        {
            var datasp = DataAll.SelectAll("PhongMau_SanPham", "*", " WHERE TrangThai =" + Convert.ToInt32(TrangThai.PhongMau_ChoDuyet));
            //lblPhongMau.Visible = datasp.Rows.Count > 0;
            lblPhongMau.Text = datasp.Rows.Count > 0 ? "Phòng mẫu gửi (" + datasp.Rows.Count + ")" : "Phòng mẫu gửi (0)";
            var datalenh = DataAll.SelectAll("LenhSanXuat", "*", " WHERE TrangThai =" + Convert.ToInt32(TrangThai.LenhSanXuat_ChoDuyet));
            //lbtnLenh.Visible = datalenh.Rows.Count > 0;
            lbtnLenh.Text = datalenh.Rows.Count > 0 ? "Phòng lệnh gửi (" + datalenh.Rows.Count + ")" : "Phòng lệnh gửi (0)";
            //lbtnLenh.Location = new Point(176, 27);
            var datakho = DataAll.SelectAll("LenhSanXuat", "*", " WHERE TrangThai =" + Convert.ToInt32(TrangThai.LenhSanXuat_ChotLenh));
            lbtnKho.Text = datakho.Rows.Count > 0 ? "Phòng lệnh (" + datakho.Rows.Count + ")" : "Phòng lệnh (0)";
            var dataKhocat = DataAll.SelectAll("LenhSanXuat", "*", " WHERE TrangThai =" + Convert.ToInt32(TrangThai.LenhSanXuat_CapNhatKho));
            lbtnPhongLenhCat.Text = datakho.Rows.Count > 0 ? "Phòng lệnh (" + dataKhocat.Rows.Count + ")" : "Phòng lệnh (0)";
            var datacatgc = DataAll.SelectAll("Cat", "*", " WHERE TrangThai =" + Convert.ToInt32(TrangThai.Cat_GuiGiaCong));
            lbtnCat.Text = datacatgc.Rows.Count > 0 ? "Tin nhắn cắt gc(" + datacatgc.Rows.Count + ")" : "Tin nhắn cắt gc(0)";
            var datacatmk = DataAll.SelectAll("Cat", "*", " WHERE TrangThai =" + Convert.ToInt32(TrangThai.Cat_GuiMayKhoan));
            lbtnCatmk.Text = datacatmk.Rows.Count > 0 ? "Tin nhắn cắt mk(" + datacatmk.Rows.Count + ")" : "Tin nhắn cắt mk(0)";
            var datacatpkcs = DataAll.SelectAll("GiaCong", "*", " WHERE TrangThai =" + Convert.ToInt32(TrangThai.GiaCong_GuiDi)
                + " OR GiaCong.TrangThai = " + Convert.ToInt32(TrangThai.MayKhoan_GuiDi));
            lbtnPhongKCS.Text = datacatpkcs.Rows.Count > 0 ? "Tin nhắn phòng KCS(" + datacatpkcs.Rows.Count + ")" : "Tin nhắn phòng KCS(0)";
            //MessageBox.Show("Có " + data.Rows.Count+ " tin nhắn ở phần mềm lương", "Message", MessageBoxButtons.OK,
            //                    MessageBoxIcon.Information);
        }

        private void lbtnLenh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            var lss = new Lss_DanhSachLenhPopup();
            lss.ShowDialog();
        }

        private void lblPhongMau_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            var pm = new DanhSachSanPhamPopup();
            pm.ShowDialog();
        }

        private void lbtnKho_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            var pm = new DanhSachLenhPopup();
            pm.ShowDialog();
        }

        private void lbtnPhongLenhCat_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            var pm = new Cat_DanhSachLenhPopup();
            pm.ShowDialog();
        }

        private void lbtnCat_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            var pm = new DanhSachCat();
            pm.ShowDialog();
        }

        private void lbtnCatmk_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            var pm = new DanhSachCatMK();
            pm.ShowDialog();
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var about = new About();
            about.ShowDialog();
        }

        private void lbtnPhongKCS_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            var about = new DanhSachMayKhoan();
            about.ShowDialog();
        }


        private void thoátToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.No;
            Close();
        }

        private void navBTaoMaSanPham_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new Phongmau_DkSanpham();
            LoadUserControl(_userControl);
        }

        private void navBVatTuHangHoa_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new VattuDuKien();
            LoadUserControl(_userControl);
        }

        private void navBDuyetSanPham_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new DuyetMau();
            LoadUserControl(_userControl);
        }

        private void navBTaoLenh_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new Lss_Dangky();
            LoadUserControl(_userControl);
        }

        private void navBDuyetLenh_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new ucDuyetLenh();
            LoadUserControl(_userControl);
        }

        private void navBLoaiVatTu_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new Kho_Loaivattu();
            LoadUserControl(_userControl);
        }

        private void navBDangKyVatTu_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new Kho_Vattu();
            LoadUserControl(_userControl);
        }

        private void navBNhapKho_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new Kho_Nhapkho();
            LoadUserControl(_userControl);
        }

        private void navBXuatKho_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new CapNhatXuatKho();
            LoadUserControl(_userControl);
        }

        private void navBChuyenKho_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new CapNhatChuyenKho();
            LoadUserControl(_userControl);
        }

        private void navBCapNhatKho_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new DanhSachLenh();
            LoadUserControl(_userControl);
        }

        private void navBKhoNoiBo_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new Kho_Khohang();
            LoadUserControl(_userControl);
        }

        private void navBSanPhamCat_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new Phongcat_Sanphamcat();
            LoadUserControl(_userControl);
        }

        private void navBPhieuYeuCau_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new Phongcat_Phieuyeucau();
            LoadUserControl(_userControl);
        }

        private void navBSPMayKhoan_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new SanPhamMayKhoan();
            LoadUserControl(_userControl);
        }

        private void navBMKPhieuYeuCau_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new MayKhoan_PhieuYeuCau();
            LoadUserControl(_userControl);
        }

        private void navBSPGiaCong_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new Giacong_Sanphamgiacong();
            LoadUserControl(_userControl);
        }

        private void navBGCPhieuYeuCau_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new Giacong_Phieuyeucau();
            LoadUserControl(_userControl);
        }

        private void navDuýetP_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new SanPhamKCS();
            LoadUserControl(_userControl);
        }

        private void navBSanPham_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new SanPhamHoanThien();
            LoadUserControl(_userControl);
        }

        private void navBDSThanhPham_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new Thanhpham_DanhsachSP();
            LoadUserControl(_userControl);
        }

        private void navBQTSanPham_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new DSChiaSPTrongCH();
            LoadUserControl(_userControl);
        }

        private void navBDSYeuCau_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new DanhSachSPTrongCuaHang();
            LoadUserControl(_userControl);
        }

        private void navBarItem16_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new DKChung_DkAnh();
            LoadUserControl(_userControl);
        }

        private void navBarItem17_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new DKChung_DKSize();
            LoadUserControl(_userControl);
        }

        private void navBarItem18_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new DKChung_DKDonVi();
            LoadUserControl(_userControl);
        }

        private void navBarItem19_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new DKChung_DKMauSac();
            LoadUserControl(_userControl);
        }

        private void navBarItem20_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new DKChung_DkNhanvien();
            LoadUserControl(_userControl);
        }

        private void navBarItem21_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new Phongmau_DkNhomhang();
            LoadUserControl(_userControl);
        }

        private void navBarItem22_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new Phongmau_DkLoaihang();
            LoadUserControl(_userControl);
        }

        private void navBarItem23_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new DKChung_DkKho();
            LoadUserControl(_userControl);
        }

        private void navBDKKhoNoiBo_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new DkChung_KhoNoiBo();
            LoadUserControl(_userControl);
        }

        private void navBDanhSachYeuCau_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {

        }

        private void navBQuaTrinhSanPham_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new Quanly_Quatrinhsanxuat();
            LoadUserControl(_userControl);
        }

        private void navBChiaSanPham_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new DanhSachChiaSP();
            LoadUserControl(_userControl);
        }

        private void navBDSSPSauChia_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new DanhSachSP();
            LoadUserControl(_userControl);
        }

        private void navBarPhieuYeuCau_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new PhieuYeuCau();
            LoadUserControl(_userControl);
        }

        private void navBarPhieuYeuCauCapThem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new PhieuYeuCauCapThem();
            LoadUserControl(_userControl);
        }

        private void navBDuyetPhieuYC_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new Lss_DuyetPhieuYeuCau();
            LoadUserControl(_userControl);
        }

        private void navBCapNhatPhieu_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new DanhSachPhieu();
            LoadUserControl(_userControl);
        }

        private void navBarLenhXuatKho_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new Kho_Xuatkho();
            LoadUserControl(_userControl);
        }

        private void navBarLenhChuyenKho_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new Kho_Chuyenkho();
            LoadUserControl(_userControl);
        }

        private void navBHTPhieuYeuCau_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new HoanThien_PhieuYeuCau();
            LoadUserControl(_userControl);
        }

        private void navBDKCuaHang_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new DKChung_DanhSachCuaHang();
            LoadUserControl(_userControl);
        }

        private void navBPhanQuyen_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            var quyen = new QuanLyPhanQuyen();
            quyen.ShowDialog();
        }

        private void navBDKAnhVT_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new DKChung_DkAnhVatTu();
            LoadUserControl(_userControl);
        }

        private void navBDSKhoChia_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new DanhSachHangTrongKho();
            LoadUserControl(_userControl);
        }

        private void navBSanPhamDaChia_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            _userControl = new DanhSachSanPham();
            LoadUserControl(_userControl);
        }
    }
}
